﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using QuanLyDuAn.BUS;

namespace QuanLyDuAn.GUI
{
    public partial class FrmMain : DevComponents.DotNetBar.Office2007RibbonForm
    {
        BackupDb backup = new BackupDb();
        public FrmChangePass frmChangePass = new FrmChangePass();
        public int permission;
        public int run = 10;
        public FrmMain()
        {
            this.WindowState = FormWindowState.Maximized;
            InitializeComponent();
            btnLogin.Enabled = true;
            buttonItem15.Enabled = false;
            buttonItem16.Enabled = false;
            rbApplicant.Enabled = false;
            rbInterviewer.Enabled = false;
            rbInterviewPlan.Enabled = false;
            rbInterviewResult.Enabled = false;
            rbVacancy.Enabled = false;
            lbBackup.Enabled = false;
            lbStore.Enabled = false;
        }
        public void ShowControl()
        {
            btnLogin.Enabled = false;
            buttonItem15.Enabled = true;
            buttonItem16.Enabled = true;
            rbApplicant.Enabled = true;
            rbInterviewer.Enabled = true;
            rbInterviewPlan.Enabled = true;
            rbInterviewResult.Enabled = true;
            rbVacancy.Enabled = true;
            lbBackup.Enabled = true;
            lbStore.Enabled = true;
        }
        public void ShowControlForInterviewer()
        {
            btnLogin.Enabled = false;
            buttonItem15.Enabled = true;
            buttonItem16.Enabled = true;
            rbApplicant.Enabled = true;
            rbInterviewer.Enabled = false;
            rbInterviewPlan.Enabled = true;
            rbInterviewResult.Enabled = true;
            rbVacancy.Enabled = true;
        }
        public void PermissionUsers()
        {
            Report.Visible = false;
        }
        
        private void ribbonBar1_ItemClick(object sender, EventArgs e)
        {

        }

        private void buttonItem1_Click(object sender, EventArgs e)
        {

        }

        private void buttonItem14_Click(object sender, EventArgs e)
        {
            FrmLogin frmLogin = new FrmLogin();
            frmLogin.Visible = true;
            frmLogin.Show();
            this.Close();
        }

        private void ribbonTabItem4_Click(object sender, EventArgs e)
        {

        }

        private void buttonItem16_Click(object sender, EventArgs e)
        {
            frmChangePass.txtNewPassword.Text = "";
            frmChangePass.txtConfirmPassword.Text = "";
            frmChangePass.Visible = true;
            frmChangePass.Show();
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            FrmWelcome frm = new FrmWelcome();
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Visible = true;
            frm.Show();
        }

        private void Help_Click(object sender, EventArgs e)
        {
            Help.ShowHelp(this, helpProvider1.HelpNamespace, HelpNavigator.TableOfContents);
        }

        private void Management_Click(object sender, EventArgs e)
        {
            if (permission == 1)
            {
                FrmVacancy frm = new FrmVacancy();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Visible = true;
                frm.permission = 1;
                frm.Show();
            }
            else
            {
                FrmVacancy frm = new FrmVacancy();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Visible = true;
                frm.permission = 2;
                frm.Permission();
                frm.Show();
            }
        }

        private void buttonItem15_Click(object sender, EventArgs e)
        {
            btnLogin.Enabled = true;
            buttonItem15.Enabled = false;
            buttonItem16.Enabled = false;
            rbApplicant.Enabled = false;
            rbInterviewer.Enabled = false;
            rbInterviewPlan.Enabled = false;
            rbInterviewResult.Enabled = false;
            rbVacancy.Enabled = false;
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void labelItem16_Click(object sender, EventArgs e)
        {
            if (permission == 1)
            {
                FrmApplicant frm = new FrmApplicant();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Visible = true;
                frm.permission = 1;
                frm.Show();
            }
            else
            {
                FrmApplicant frm = new FrmApplicant();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Visible = true;
                frm.permission = 2;
                frm.Permission();
                frm.Show();
            }
        }

        private void Report_Click(object sender, EventArgs e)
        {
            FrmStatisticsVacancy frm = new FrmStatisticsVacancy();
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Visible = true;
            frm.Show();
        }

        private void labelItem7_Click(object sender, EventArgs e)
        {
            FrmSearchVacancy frm = new FrmSearchVacancy();
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Visible = true;
            frm.Show();
        }

        private void labelItem12_Click(object sender, EventArgs e)
        {
            FrmInterviewer frm = new FrmInterviewer();
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Visible = true;
            frm.Show();
           
        }

        private void labelItem9_Click(object sender, EventArgs e)
        {
            FrmSearchInterviewer frm = new FrmSearchInterviewer();
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Visible = true;
            frm.Show();
        }

        private void labelItem13_Click(object sender, EventArgs e)
        {
            FrmSearchApplicant frm = new FrmSearchApplicant();
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Visible = true;
            frm.Show();
        }

        private void labelItem20_Click(object sender, EventArgs e)
        {
            if (permission == 1)
            {
                FrmInterviewPlan frm = new FrmInterviewPlan();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Visible = true;
                frm.permission = 1;
                frm.Show();
            }
            else
            {
                FrmInterviewPlan frm = new FrmInterviewPlan();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Visible = true;
                frm.permission = 2;
                frm.Permission();
                frm.Show();
            }
        }

        private void labelItem17_Click(object sender, EventArgs e)
        {
            FrmSearchInterviewPlan frm = new FrmSearchInterviewPlan();
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Visible = true;
            frm.Show();
        }

        private void labelItem24_Click(object sender, EventArgs e)
        {
            FrmIterviewResult frm = new FrmIterviewResult();
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Visible = true;
            frm.Show();
        }

        private void ribbonBar7_ItemClick(object sender, EventArgs e)
        {
            FrmStatisticsInterview frm = new FrmStatisticsInterview();
            frm.MdiParent= this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Visible= true;
            frm.Show();
        }

        private void labelItem10_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            
            lbUser.Left += run;
            if (lbUser.Left >= this.Width - lbUser.Width || lbUser.Left <= this.Width/2)
                run = -run;
        }

        private void labelItem14_Click(object sender, EventArgs e)
        {
            FrmStatisticsApplicant frm = new FrmStatisticsApplicant();
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Visible = true;
            frm.Show();
        }

        private void labelItem18_Click(object sender, EventArgs e)
        {
            FrmStaticInterviewPlan frm = new FrmStaticInterviewPlan();
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Visible = true;
            frm.Show();
        }

        private void labelItem21_Click(object sender, EventArgs e)
        {
            FrmSearchInterviewResult frm = new FrmSearchInterviewResult();
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Visible = true;
            frm.Show();
        }

        private void lbBackup_Click(object sender, EventArgs e)
        {
            String month = DateTime.Now.Month.ToString();
            String year = DateTime.Now.Year.ToString();
            String day = DateTime.Now.Day.ToString();
            String hour = DateTime.Now.Hour.ToString();
            String minutes = DateTime.Now.Minute.ToString();
            String datetime = day + month + year + hour + minutes;
            String filename = datetime + ".bak";
            if (MessageBox.Show("You Really Want To Backup Database?", "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                backup.BackupData(filename);
                MessageBox.Show("Backup Database is successful! ");
            }
        }

        public String FileNameBackup()
        {
            OpenFileDialog diagOpen = new OpenFileDialog();
            diagOpen.Filter = "bak|*.bak;";
            diagOpen.Multiselect = false;
            diagOpen.ShowDialog();
            String s = diagOpen.FileName;
            String fileName = s.Substring(s.LastIndexOf('\\') + 1);
            return fileName;
           
        }
        private void labelItem22_Click(object sender, EventArgs e)
        {
            String fileName = this.FileNameBackup();
            if (fileName.CompareTo("") != 0)
            {
                if (MessageBox.Show("You Really Want To ReStore Database?", "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    backup.RestoreData(fileName);
                    MessageBox.Show("Restore Database is Successful! ");
                }
            }
        }
                
    }
}
